package entity;

import java.util.List;

/**
 * Values and methods for specifying the PRIORITY property
 * for the iCalendar object as defined in RFFC 5545. This
 * property defines the relative priority for a calendar 
 * component.
 * 
 * @author Sean Young
 * @version 1.0
 *
 */
public class Priority {
        
        /** A string containing the parameters for the PRIORITY property */
        private String prioparam;
        
        /** The value of the PRIORITY property */
        private int priovalue;
        
        /**
         * Constructor for the PRIORITY property. Parameters are defaulted
         * to null and the value is defaulted to 0 (undefined).
         */
        public Priority() {
                prioparam = null;
                priovalue = 0;
        }
        
        /**
         * Constructor for the PRIORITY property. Sets the value of the 
         * PRIORITY property to the value specified in the parameter.
         * @param priority The level of priority
         *                 0 = undefined, 1 = Highest, 2 = Second Highest, etc.
         */
        public Priority(int priority) {
                prioparam = null;
                priovalue = priority;
        }
        
        /**
         * Sets the parameters for the PRIORITY property. Must be a single parameter.
         * @param prioparam The parameter to be added to the PRIORITY property.
         *                   The parameter must be a single parameter.
         */
        public void setPrioParam(String prioparam) {
                this.prioparam = prioparam;
        }
        
        /**
         * Sets the value of the parameter for the PRIORITY property.
         * @param prioparams A list of parameters to be added to the PRIORTY
         *                    property. 
         */
        public void setPrioParam(List<String> prioparams) {
                StringBuilder parameterBuilder = new StringBuilder(" ");
                for(int i = 0; i < prioparams.size(); i++) {
                        parameterBuilder.append(prioparams.get(i));
                        if((prioparams.size() != 1) && (i != prioparams.size() - 1)) parameterBuilder.append(";");
                }
                this.prioparam = parameterBuilder.toString();
        }
        
        /**
         * Sets the value of the PRIORITY property.
         * @param priority The level of priority
         *                 0 = undefined, 1 = Highest, 2 = Second Highest, etc.
         */
        public void setPriority(int priority) {
                this.priovalue = priority;
        }
        
        /**
         * Returns a string containing the values of the fields of the
         * PRIORITY property. If no parameters were specified then they 
         * will not be included.
         */
        public String toString() {
                StringBuilder prioString = new StringBuilder("PRIORITY");
                
                if(prioparam != null) prioString.append(prioparam);
                
                prioString.append(":");
                
                prioString.append(priovalue);
                prioString.append("\r\n");
                
                return prioString.toString();
        }
}